package com.yanqu.road.server.cmd.strongholdwar.eliminate;

import com.yanqu.road.entity.activity.stronghold.config.StrongholdEliminateReportDetail;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.strongholdwar.CrossStrongholdMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.C_ROSS_STRONGHOLD_ELIMINATE_REPORT_DETAIL, desc = "")
public class CrossGetEliminateReportDetailCmd extends CrossUnionCommand {
    private int activityId;
    private int id;
    private int type;
    private long userId;
    private int id2;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        StrongholdWarProto.CrossGetEliminateReportDetailReqMsg req = StrongholdWarProto.CrossGetEliminateReportDetailReqMsg.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        id = req.getId();
        type = req.getType();
        userId = packet.getPlayerId();
        id2 = req.getId2();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        List<StrongholdEliminateReportDetail> detailList = CrossStrongholdMgr.getEliminateReportDetail(activityId, groupId, id, type, id2);
        StrongholdWarProto.GetEliminateReportDetailRespMsg.Builder resp = StrongholdWarProto.GetEliminateReportDetailRespMsg.newBuilder();
        for (StrongholdEliminateReportDetail detail : detailList) {
            StrongholdWarProto.StrongholdEliminateReportDetailMsg.Builder msg = StrongholdWarProto.StrongholdEliminateReportDetailMsg.newBuilder();
            msg.setNickName(detail.getNickName());
            msg.setDamage(detail.getDamage().toString());
            resp.addReport(msg);
        }
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(ClientProtocol.U_STRONGHOLD_WAR_ELIMINATION_MEMBER_DAMAGE, resp);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
